# Using the official Node.js 22-slim image as the base image
FROM node:22-slim

# Install PostgreSQL client (psql) and other system deps
RUN apt-get update && \
    apt-get install -y postgresql-client dos2unix && \
    rm -rf /var/lib/apt/lists/*

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and lock file first
COPY package*.json ./

# copy init.sql
COPY init.sql /docker-entrypoint-initdb.d/

# copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
RUN dos2unix /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT [ "/usr/local/bin/docker-entrypoint.sh" ]

# Copy the distribution files
COPY /dist .

# Set environment variables file
# ENV NODE_ENV=development

RUN echo "Starting the service"
#run the MQTT client on start
CMD ["node", "index.js"]


